(function(window) {
	var vm;
	var commonLocale = dataManager.getLocale();

	function logout() {
		v3AppApi.logout(function(code) {
			if(code == 0) {
				dataManager.logout();
				notifyLogoutSuccess();
			} else if(code == 1){
				commonTool.toast(commonLocale.logoutFailTips);
			}
		});
	}

	function notifyLogoutSuccess() {
		var indexPage = plus.webview.getLaunchWebview();
		$.fire(indexPage, 'LogoutSuccess', {
			index: vm.activeIndex
		});
	}

//	function saveQrCode() {
//		plus.nativeUI.actionSheet({
//			cancel: commonLocale.actionSheet.cancelTips,
//			buttons: [{
//				title: commonLocale.actionSheet.buttonTips
//			}]
//		}, function(e) {
//			var index = e.index;
//			if(e.index === 1) {
//				plus.gallery.save("_www/images/lvzhouqr.png", function() {
//					mui.toast(commonLocale.saveQrSuccessTips);
//				}, function(error) {
//					console.log("error");
//					mui.toast(error.message);
//				});
//			}
//		});
//	}

//	window.addEventListener('refresh', function() {
//		$.plusReady(function() {
//			vm.userName = dataManager.getUserName();
//		});
//	});

	window.addEventListener('headImgLoad', function(e) {
		convertImg(e.detail.img, function(img) {
			vm.headImg = img;
		});
	});

	window.profile = {
		methods: {
//			saveQrCode: saveQrCode,
			logout: logout
		},
		mounted: function() {
			vm = this;
			$.plusReady(function() {
				$.init({
					gestureConfig: {
//						longtap: true,  长按
						swipeBack: true
					}
				});
				vm.userName = dataManager.getUserName();
			});
		}
	};
})(window);